*****************************************	
**# A. Concord TSUSA price growth to SIC 
*****************************************
use "raw/sitc_prices_imports.dta", clear
egen id = group(sitc2)
xtset id year
gen dln_pstar_vw_l7 = - l7.dln_pstar_vw if year==1979
gen dln_pstar_vw_f9 = f9.dln_pstar_vw if year==1979

keep if year == 1979
keep sitc2 imports_c2 dln_pstar_vw*
drop dln_pstar_vw
rename dln_pstar_vw_f9 dln_pstar_vw

joinby sitc2 using "processing/sitc2_sic_concordance.dta", unmatched(both)
tab _m
	* m=1: 64 obs (3.84%) only in tariff data and not in concordance
	* m=2: 169 obs (8.53%) in concordance but not in tariff data
keep if _m == 3
drop _m

**********************************
**# B. Calculate SIC price growth
**********************************
gen imports_w = imports_c2 if dln_pstar_vw!=.
gen imports_w_l7 = imports_c2 if dln_pstar_vw_l7!=.

replace imports_w   = imports_w*sitc_sic_weight
replace imports_w_l7 = imports_w_l7*sitc_sic_weight
	* weights sum to 1 within sitc, so weights split sitc across constituent sic

bys sic : egen timp = total(imports_w)
bys sic : egen timp_l7 = total(imports_w_l7)

gen ishare = imports_w/timp
gen ishare_l7 = imports_w_l7 / timp_l7

gen dln_pstar_vw_7988_alt = ishare*dln_pstar_vw		/ 9
gen dln_pstar_vw_7279_alt = ishare_l7 * dln_pstar_vw_l7 /7

collapse (sum) dln_pstar_vw_7*, by(sic)
drop if substr(sic,4,1) == "X"
destring sic, replace
keep if sic>=2000 & sic < 4000
drop dln_pstar_vw_7988_alt 
save "processing/sic_price_growth.dta", replace